version 14
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.VI OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

*-----------------------------------
* 	WITH CONTROLS
*-----------------------------------

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==0
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc location_code
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* GENERATING TREATMENT DUMMIES */

g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011

/* COLUMN (1) -- BASELINE */

local			i=1
local			j=1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor)  
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (2) -- DROPPING BUNCHERS */

preserve
local			i=1
matrix 			input bunch_se=   (100,2\110,2\125,3\150,5\175,3\200,5\300,5\400,10\500,15\600,5)	
g				buncher=0
forvalues 		n_notch=1(1)10 {
				local notch=bunch_se[`n_notch',1]*1000
				local lower=`notch' - (bunch_se[`n_notch',2]*1000)
				replace buncher=1 if taxableinc>`lower' & taxableinc<=`notch'
}
drop			if buncher==1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1
restore

/* COLUMN (3) -- DROPPING TAXPAYERS CLOSE TO 50% THRESHOLD */

g				share_se=seinc/taxableinc
drop 			if share>0.45 & share<=0.55
local			i=1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (4) -- FULL SAMPLE */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
sort			regnor year
local 			var="seinc"
keep			if employee==0
keep 			`var' regnor year industry2 taxableinc
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
qui				sum logchange,d
keep 			if z0<=500000
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011
g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011
local			i=1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (5) -- FULL SAMPLE */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
sort			regnor year
local 			var="seinc"
keep			if employee==0
keep 			`var' regnor year industry2 taxableinc
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011
g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011
local			i=1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (6) -- INDUSTRY DUMMIES AS ADDITIONAL CONTROLS */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==0
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000
keep 			`var' regnor year industry2 taxableinc location_code industry2 tax_office_id
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011
g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011
local			i=1
qui				reg logchange i.year i.industry2 tozero nottozero m_09 m_10 t_09 if industry2>0, cluster(regnor)  
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (7) -- CITY DUMMIES AS ADDITIONAL CONTROLS */

local			i=1
qui				reg logchange i.year i.location_code tozero nottozero m_09 m_10 t_09  if location_code>=0, cluster(regnor)  
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (8) -- TAX OFFICE DUMMIES AS ADDITIONAL CONTROLS */

local			i=1
qui				reg logchange i.year i.tax_office_id tozero nottozero m_09 m_10 t_09, cluster(regnor)  
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (9) -- CITY, TAX OFFICE, AND INDUSTRY DUMMIES TOGETHER AS CONTROLS */

local			i=1
qui				reg logchange i.year i.industry2 i.location_code i.tax_office_id tozero nottozero m_09 m_10 t_09  if location_code>=0 &  industry2>0, cluster(regnor)  
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)
local			j=`j'+1

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
keep			if _n<=8
g				c11=""
replace			c11="$\mbox{\emph{to-zero}} \times \mbox{\emph{SE}} \times 2009$" in 1
replace			c11="$\mbox{\emph{to-zero}} \times \mbox{\emph{SE}} \times 2010$" in 3
replace			c11="$\mbox{\emph{not-to-zero}} \times \mbox{\emph{SE}} \times 2009$" in 5
replace			c11="Observations" in 7
forvalues 		c=1/9 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)6 {
forvalues		c=1/9 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/9 {
replace			c`c'=string(table`c',"%15.0fc") in 7
}
forvalues		s=1/10 {
g				s`s'="&"
}
g				l="\\"
replace			l="\\\\" in 6
browse			c11 s10 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 s7 c8 s8 c9 l
